﻿using System;
using System.Data;
using Bank.DataSets;
using Bank.DataAccess;
using Bank.DTOs;
using System.Web;

public partial class ADODotNet_Customers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //btnAdd_Click version 1.0
    //protected void btnAdd_Click(object sender, EventArgs e)
    //{
    //    CustomerData datacust = new CustomerData();
    //    DataSet dscust = datacust.GetCustomer(); //get local copy

    //    DataRow custRow = dscust.Tables["CustLocal"].NewRow();
    //    custRow["CustomerName"] = txtName.Text;
    //    custRow["BalanceAmt"] = Convert.ToDouble(txtBalAmt.Text);
    //    custRow["BankAcNo"] = txtAcNo.Text;

    //    dscust.Tables["CustLocal"].Rows.Add(custRow);

    //    datacust.UpdateToDataBase(dscust);
    //}

    //btnAdd_Click version 2.0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        DsCustomer dscust = (DsCustomer)Session["CustDataSet"];
        if (dscust == null)
        {
            dscust = new DsCustomer();
        }
        DataRow custRow = dscust.Customer.NewRow();
        custRow["CustomerName"] = txtName.Text;
        custRow["BalanceAmt"] = Convert.ToDouble(txtBalAmt.Text);
        custRow["BankAcNo"] = txtAcNo.Text;
        dscust.Customer.Rows.Add(custRow);

        Session["CustDataSet"] = dscust;
    }

    protected void btnUpdateDB_Click(object sender, EventArgs e)
    {
        CustomerData datacust = new CustomerData();
        DsCustomer dscust = (DsCustomer)Session["CustDataSet"];
        if (dscust != null)
            datacust.UpdateToDataBase(dscust);
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        CustomerData cdata = new CustomerData();
        int r = cdata.CheckUser(txtAcNo.Text);
        if (r > 0)
            Response.Redirect("~/StateManagement/ViewState1.aspx");
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        CustomerData custdataOnj = new CustomerData();
        DsCustomer dscust = custdataOnj.GetCustomer();
        DataRow[] drs = dscust.Tables[dscust.Customer.TableName].Select("BankAcNo='" + txtAcNo.Text + "'");
        foreach (DataRow dr in drs)
            dscust.Tables[dscust.Customer.TableName].Rows.Remove(dr);

        custdataOnj.UpdateToDataBase(dscust);
    }

}
